package com.qiguliuxing.dts.service.base;

import com.github.pagehelper.PageHelper;
import com.qiguliuxing.dts.db.dao.DtsManagerLogMapper;
import com.qiguliuxing.dts.db.domain.DtsManagerLog;
import com.qiguliuxing.dts.db.domain.DtsManagerLogExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DtsManagerLogService {

	@Resource
	private DtsManagerLogMapper managerLogMapper;

	public List<DtsManagerLog> queryAll() {
		DtsManagerLogExample example = new DtsManagerLogExample();
		example.or();
		return managerLogMapper.selectByExample(example);
	}

	public List<DtsManagerLog> querySelective(String username, String methodDesc, Integer page, Integer limit, String sort, String order) {
		DtsManagerLogExample example = new DtsManagerLogExample();
		DtsManagerLogExample.Criteria criteria = example.createCriteria();

		if (!StringUtils.isEmpty(username)) {
			criteria.andUsernameLike("%" + username+ "%");
		}
		if (!StringUtils.isEmpty(methodDesc)) {
			criteria.andMethodDescLike("%" + methodDesc + "%");
		}

		if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
			example.setOrderByClause(sort + " " + order);
		}

		PageHelper.startPage(page, limit);
		return managerLogMapper.selectByExample(example);
	}

	public void deleteById(Integer id) {
		managerLogMapper.deleteByPrimaryKey(id);
	}
}
